<?php

namespace Admin\Controller;

use Admin\Form\AdminForm;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class AdminController extends AbstractActionController
{
    protected $admin;
    protected $adminTable;

    /**
     * @return array|object
     */
    public function getAdminTable()
    {
        if (!$this->adminTable) {
            $sm = $this->getServiceLocator();
            $this->adminTable = $sm->get('Admin\Model\AdminTable');
        }
        return $this->adminTable;
    }

    public function indexAction()
    {
        $form = new AdminForm();
        $this->admin = $this->getAdminTable()->getLoginAdmin();
        $form->bind($this->admin);
        $form->get('submit')->setAttribute('value', '确定')->setAttribute('class', 'btn btn-primary');
        $view = new ViewModel(array(
            'form' => $form,
            'admin' => $this->admin
        ));
        return $view;
    }
}